<template>
  <page-wrap dark hideTab title="审核结果" stayStill needLogin>
    <view class="cert-result u-text-center">
      <view v-if="type == 1" class="ing">
        <image class="result-img" :src="resultIngImg" mode="" />
        <view class="tips">
          <view class="tips-title">资料审核中</view>
          <view class="tips-lable">审核预计需要1—3个工作日，请您耐心等待</view>
          <view class="btn btn-primary u-m-t-32" @click="refresh"> 刷新 </view>
          <view class="btn-text u-m-t-24" @click="toPerson"> 前往企业端 </view>
        </view>
      </view>
      <view v-else-if="type == 2" class="fail">
        <image class="result-img" :src="resultFailImg" mode="" />
        <view class="tips u-m-b-60">
          <view class="tips-title" @click="auditSuccess">认证失败</view>
          <view class="tips-lable u-text-left"
            >您未通过认证，具体的原因为：</view
          >
          <view class="tips-lable reason">{{ checkReason }}</view>
          <view class="tips-lable tips-lable-small u-text-left"
            >若您想要重新上传营业执照或在职证明，请点击下方“重新认证”按钮；若您想要修改企业信息，请点击“更多选择”，选择“变更企业”</view
          >
        </view>
        <view class="action">
          <view class="btn btn-primary u-m-b-24" @click="certAgain"
            >重新认证</view
          >
          <view class="more" @click="showMore = true">更多选择</view>
        </view>
      </view>

      <view class="bottom">
        <view class="tips" @click="handleCall('400-884-1001')">
          <text
            >客服热线：<text class="tel">400-884-1001</text>（8:00-18:00）</text
          >
        </view>
      </view>
      <u-icon
        name="more-dot-fill"
        size="52"
        class="btn-more"
        @click="showMore = true"
      ></u-icon>
    </view>
    <MoreAction :show.sync="showMore" :isShowChange="isShowChange" />
  </page-wrap>
</template>

<script>
import { checkPersonAudit } from '@/api/modules/company';
import MoreAction from '../components/moreAction.vue';
export default {
  components: {
    MoreAction
  },
  data() {
    return {
      resultIngImg: this.$imgBase + 'company/cert_audit.png',
      resultFailImg: this.$imgBase + 'company/cert_fail.png',
      type: 0,
      showMore: false,
      info: {},
      personId: uni.getStorageSync('person-id').slice(2) || undefined,
      companyId: uni.getStorageSync('company-id'),
      checkReason: '',
      resultInfo: {},
      applyDataType: '',
      isShowChange: true
    };
  },
  onShow() {
    uni.hideHomeButton();
  },
  onLoad(opt) {
    this.type = opt.type;
    if (this.type == 1) {
      this.isShowChange = false;
    }
  },
  mounted() {
    if (this.type) return;
    this.getData();
  },
  methods: {
    getData() {
      // let params = {
      //   person_id: this.personId,
      //   company_id: this.companyId,
      // }
      uni.showLoading();
      // getFailInfo(params).then(res => {
      //   uni.hideLoading();
      //   if(res.code == 200 || res.code == 101) { // 200 审核中, 101 没有申请记录
      //     this.type = 1;
      //   } else if(res.code == 201) { // 审核通过
      //     this.auditSuccess()
      //   } else { // 审核失败
      //     this.type = 2;
      //     this.resultInfo = res.info;
      //     // this.checkReason = res.info.check_reason;
      //   }
      // }).catch(res => {
      //     uni.hideLoading();
      // });
      let params = {
        personId: this.personId,
        companyId: this.companyId
      };
      checkPersonAudit(params)
        .then((res) => {
          uni.hideLoading();
          if (res && res.code == 200) {
            // 审核通过
            this.auditSuccess();
          } else if (res && res.code == 202) {
            // 审核中
            this.type = 1;
            this.isShowChange = false;
          } else if ((res && res.code == 203) || (res && res.code == 206)) {
            // 营业执照审核失败 206：需要上传营业执照
            this.type = 2;
            this.applyDataType = 1;
            this.checkReason = res.data.checkReason;
            this.isShowChange = true;
          } else if ((res && res.code == 204) || (res && res.code == 205)) {
            // 在职证明审核失败 205:需要上传营业执照
            this.type = 2;
            this.applyDataType = 2;
            this.checkReason = res.data.checkReason;
            this.isShowChange = true;
          } else {
            uni.showToast({
              title: res.status_desc,
              icon: 'none'
            });
          }
        })
        .catch((res) => {
          uni.hideLoading();
        });
    },
    certAgain() {
      // const type = this.resultInfo.apply_data_type || '';
      uni.navigateTo({
        url: '/pagesSub/company/selectCert/index?type=' + this.applyDataType
      });
    },
    auditSuccess() {
      uni.redirectTo({
        url: '/pages/company/index?showAudit=1'
      });
    },
    // 拨打电话
    handleCall(mobile) {
      uni.makePhoneCall({
        phoneNumber: mobile
      });
    },
    refresh() {
      this.getData();
    },
    toPerson() {
      // uni.navigateTo({
      //   url: '/pagesSub/public/character/index'
      // });
      uni.reLaunch({
        url: '/pages/library/index'
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.cert-result {
  flex: 1;
  padding: $uni-spacing-col-big;
  padding-top: 140rpx;
  background-color: $uni-bg-color;
  .result-img {
    display: inline-block;
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 30rpx;
  }
  .tips {
    font-size: $uni-font-size-base;
    color: $uni-text-color-666;
    &-title {
      margin-bottom: 20rpx;
      font-size: 36rpx;
      font-weight: bold;
      color: #000;
    }

    &-lable-small {
      font-size: 24rpx;
      color: #999999;
    }
  }
  .action {
    font-size: $uni-font-size-lg;
    .more {
      color: $u-type-primary;
    }
  }
  .bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background-color: $uni-bg-color;
    padding: 32rpx;
    padding-bottom: calc(32rpx + constant(safe-area-inset-bottom));
    padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
    .tips {
      text-align: center;
      font-size: $uni-font-size-sm;
      color: $uni-text-color-999;
      .tel {
        color: $u-type-primary;
      }
    }
  }
  .btn-more {
    position: absolute;
    right: 30rpx;
    top: 20rpx;
  }

  .fail {
    .reason {
      margin: 24rpx 0;
      font-size: 28rpx;
      color: $u-type-primary;
    }
  }

  .btn-text {
    font-size: 32rpx;
    color: $u-type-primary;
  }
}
</style>
<style lang="scss">
.result.sucesss {
  .result-img {
    display: inline-block;
    width: 200rpx;
    height: 200rpx;
    margin-bottom: 30rpx;
  }
}
</style>
